<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 题库
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                    <el-select v-model="query.state" :placeholder="hideSolve == 1 ? '隐藏已解出的问题' : '显示已解出的问题' " class="handle-select mr10">
                    <el-option key="1" label="隐藏已解出的问题" value="隐藏已解出的问题"></el-option>
                    <el-option key="2" label="显示已解出的问题" value="显示已解出的问题"></el-option>
                </el-select>
                <el-input v-model="query.probID" placeholder="问题编号" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="probID" label="题号"></el-table-column>
                <el-table-column label="题目名称">
                    <template #default="scope"><a :href="scope.row.url">{{ scope.row.name }}</a></template>
                </el-table-column>
                <el-table-column prop="tag" label="标签"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template #default="scope">
                        <el-tag class="tag"
                            v-if="scope.row.state !== ''"
                            :type="scope.row.state==='success'?'success':(scope.row.state==='failed'?'danger':'')"
                        >{{scope.row.state}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="difficulty" label="难度"></el-table-column>
                <el-table-column prop="solved" label="通过人数"></el-table-column>
<!--                <el-table-column label="前往题目">-->
<!--                    <template #default="scope">-->
<!--                        <a :href="scope.row.url"></a>-->
<!--                    </template>-->
<!--                </el-table-column>-->
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

    </div>
</template>

<script>
import { fetchProblem } from '../api/index';
export default {
    name: 'problem',
    data() {
        return {
            query: {
                state: '',
                probID: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            hideSolve: 0
        };
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            fetchProblem(this.query).then(res => {
                console.log(res);
                this.tableData = res.list;
                this.pageTotal = res.pageTotal || 50;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 1.2em;
}
.tag{
    font-size: 1.0em;
}
.mr10 {
    margin-right: 10px;
}
a{
    color: #20a0ff;
}
</style>
